package com.example.book.in.controller;

import com.example.book.base.BaseController;
import com.example.book.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.example.book.in.entity.UserBookshelf;
import com.example.book.in.service.UserBookshelfService;


/**
 * @author   hcj
 * @date 2019-12-12 15:13:55
*/
@Controller
@RequestMapping(value = "/userBookshelf")
public class UserBookshelfController extends BaseController{

    @Autowired
    private UserBookshelfService userBookshelfService;

    @ModelAttribute
    public UserBookshelf get(@RequestParam(required=false) String id) {
        if (StringUtils.isNotBlank(id)){
            UserBookshelf userBookshelf = new UserBookshelf();
            userBookshelf.setId(id);
            return userBookshelfService.get(userBookshelf);
        }else{
            return new UserBookshelf();
        }
    }

    @RequestMapping(value = "/get")
    @ResponseBody
    public UserBookshelf getById(UserBookshelf userBookshelf) {
        return userBookshelf;
    }

    @RequestMapping(value = "/list")
    public String list(UserBookshelf userBookshelf) {
        return "userBookshelf";
    }

    @RequestMapping(value = "/info")
    @ResponseBody
    public List<UserBookshelf> info(UserBookshelf userBookshelf) {
        return userBookshelfService.findList(userBookshelf);
    }


    @RequestMapping(value = "/findPage")
    @ResponseBody
    public PageInfo<UserBookshelf> findPage(UserBookshelf userBookshelf) {
        return  userBookshelfService.findPage( userBookshelf);
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public Result save(UserBookshelf userBookshelf) {
        userBookshelfService.save(userBookshelf);
        return Result.success("保存成功");
    }

    @RequestMapping(value = "/logicalDeletion",method = RequestMethod.POST)
    @ResponseBody
    public Result logicalDeletion(@RequestParam("id") String id){
        userBookshelfService.logicalDeletion(id);
        return Result.success();
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam("ids") String[] ids){
        userBookshelfService.delete(ids);
        return Result.success();
    }

}